package org.example.managere.dto.feibiao;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.util.Date;

/**
 * 电机故障信息数据传输对象 - 电机向量知识库
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class AmKnowledgeFailureDto {
    private Integer id;
    
    @NotEmpty(message = "电机ID不能为空")
    @Size(max = 10, message = "电机ID长度不能超过10")
    private String motorId;
    
    @NotNull(message = "故障时间不能为空")
    private Date failureTime;
    
    @NotNull(message = "故障发现时间不能为空")
    private Date discoveryTime;
    
    private Date repairTime;
    
    @NotEmpty(message = "故障类型不能为空")
    @Size(max = 50, message = "故障类型长度不能超过50")
    private String failureType;
    
    @NotEmpty(message = "故障描述不能为空")
    private String failureDescription;
    
    @NotEmpty(message = "故障原因不能为空")
    @Size(max = 100, message = "故障原因长度不能超过100")
    private String failureCause;
    
    @NotEmpty(message = "维修措施不能为空")
    private String repairMeasures;
    
    private Date createdAt;
    
    private Date updatedAt;
    
    // 添加额外字段以便前端显示
    private String motorType;
    private String manufacturer;
    
    // 计算字段
    public boolean isRepaired() {
        return repairTime != null;
    }
    
    public long getResponseTimeInMinutes() {
        if (discoveryTime == null || failureTime == null) {
            return 0;
        }
        return (discoveryTime.getTime() - failureTime.getTime()) / (1000 * 60);
    }
    
    public long getRepairTimeInHours() {
        if (repairTime == null || discoveryTime == null) {
            return 0;
        }
        return (repairTime.getTime() - discoveryTime.getTime()) / (1000 * 60 * 60);
    }
} 